﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection connection = new SqlConnection(GlobalConstant.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }
    }
 


    protected void btnAdd_Click(object sender, EventArgs e)
    {
        connection.Open();
        SqlCommand cmd;
        string sql;

        sql = "INSERT INTO tbStaff VALUES(@p01, @p02, @p03, @p04, @p05, @p06, @p07" +
            ", @p08, @p09, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, @p20, @p21" +
            ")";
        cmd = new SqlCommand();
        cmd.Connection = connection;
        cmd.CommandText = sql;
        cmd.Parameters.AddWithValue("p01", (Staff.FindControl("txtFirstName") as TextBox).Text);
        cmd.Parameters.AddWithValue("p02", (Staff.FindControl("txtLastName") as TextBox).Text);
        cmd.Parameters.AddWithValue("p03", (Staff.FindControl("txtAddress") as TextBox).Text);
        cmd.Parameters.AddWithValue("p04", (Staff.FindControl("liSex") as DropDownList).SelectedIndex);
        cmd.Parameters.AddWithValue("p05", (Staff.FindControl("dpDOB") as Management_DatePicker).Date);
        cmd.Parameters.AddWithValue("p06", (Staff.FindControl("txtTel") as TextBox).Text);
        cmd.Parameters.AddWithValue("p07", (Staff.FindControl("txtInsNum") as TextBox).Text);
        cmd.Parameters.AddWithValue("p08",Staff.getIDPositionByName((Staff.FindControl("liPoSition")as DropDownList).SelectedItem.ToString()));
        cmd.Parameters.AddWithValue("p09", Staff.getIDWardByName((Staff.FindControl("liWard") as DropDownList).SelectedItem.ToString()));
        cmd.Parameters.AddWithValue("p10", (Staff.FindControl("txtCurSalary") as TextBox).Text);
        cmd.Parameters.AddWithValue("p11", (Staff.FindControl("txtSalaryScale") as TextBox).Text);
        cmd.Parameters.AddWithValue("p12", (Staff.FindControl("txtHourperWeek") as TextBox).Text);
        cmd.Parameters.AddWithValue("p13", (Staff.FindControl("liPaid") as DropDownList).SelectedValue);
        cmd.Parameters.AddWithValue("p14", (Staff.FindControl("liWork") as DropDownList).SelectedValue);
        cmd.Parameters.AddWithValue("p15", (Staff.FindControl("txtQtype") as TextBox).Text);
        cmd.Parameters.AddWithValue("p16", (Staff.FindControl("dpQDate") as Management_DatePicker).Date);
        cmd.Parameters.AddWithValue("p17", (Staff.FindControl("txtQIns") as TextBox).Text);
        cmd.Parameters.AddWithValue("p18", Staff.getIDPositionByName((Staff.FindControl("liPoSition") as DropDownList).SelectedItem.ToString()));
        cmd.Parameters.AddWithValue("p19", (Staff.FindControl("dpStart") as Management_DatePicker).Date);
        cmd.Parameters.AddWithValue("p20", (Staff.FindControl("dpFinish") as Management_DatePicker).Date);
        cmd.Parameters.AddWithValue("p21", (Staff.FindControl("txtEOrganization") as TextBox).Text);
        int check = cmd.ExecuteNonQuery();
        if (check!=null)
        {
            Response.Write("<script>alert('Thêm nhân viên thành công!');</script>");
            (Staff.FindControl("txtFirstName") as TextBox).Text = "";
            (Staff.FindControl("txtLastName") as TextBox).Text = "";
            (Staff.FindControl("txtAddress") as TextBox).Text = "";
            (Staff.FindControl("dpDOB") as Management_DatePicker).Text = "";
            (Staff.FindControl("txtTel") as TextBox).Text = "";
            (Staff.FindControl("txtInsNum") as TextBox).Text="";
            (Staff.FindControl("txtCurSalary") as TextBox).Text = "";
            (Staff.FindControl("txtSalaryScale") as TextBox).Text = "";
            (Staff.FindControl("txtHourperWeek") as TextBox).Text = "";
            (Staff.FindControl("txtQtype") as TextBox).Text = "";
            (Staff.FindControl("dpQDate") as Management_DatePicker).Text = "";
            (Staff.FindControl("txtQIns") as TextBox).Text = "";
            (Staff.FindControl("dpStart") as Management_DatePicker).Text = "";
            (Staff.FindControl("dpFinish") as Management_DatePicker).Text = "";
            (Staff.FindControl("txtEOrganization") as TextBox).Text = "";
        }
        connection.Close();
    }
}
